package com.tools;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.bean.article;
import com.bean.contents;


public class FrontPage_JOSN {
	public article josn(String result) throws JSONException {
		JSONObject object = new JSONObject(result);
		JSONObject object2 = object.getJSONObject("paramz");
		JSONObject articleobj = object2.getJSONObject("article");
		article article = new article();
		article.setId(articleobj.getString("id"));
		article.setCategory(articleobj.getString("category"));
		article.setSubject(articleobj.getString("subject"));
		article.setSummary(articleobj.getString("summary"));
		article.setOrigin(articleobj.getString("origin"));
		article.setOrigined(articleobj.getString("origined"));
		article.setSubtitle(articleobj.getString("subtitle"));
		JSONArray jsonArray = articleobj.getJSONArray("contents");
		ArrayList<contents> contents = new ArrayList<contents>();
		for (int i = 0; i < jsonArray.length(); i++) {
			JSONObject object3 = jsonArray.getJSONObject(i);
			contents content = new contents();
			if(object3.isNull("link")){
				content.setCategory(object3.getString("category"));
				content.setText(object3.getString("text"));
				content.setLink("null");
			}else {
				content.setLink(object3.getString("link"));
				content.setCategory(object3.getString("category"));
				content.setText("null");
			}
			
			contents.add(content);
		}
		article.setContents(contents);
		
		return article;

	}
}
